#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>

struct PersonInfo
{
    std::string name;
    std::vector<std::string> phones;
};

std::string format(const std::string &s)
{
    return s;
}

bool valid(const std::string &s)
{
    return true;
}

int main(int argc, char *argv[])
{
    std::string line, word;
    std::vector<PersonInfo> people;
    std::istringstream record;

    if(argc != 2)
    {
        std::cerr << "Please input file name." << std::endl;
        return -1;
    }

    std::ifstream in(argv[1]);
    if(!in)
    {
        std::cerr << "Cann't open input file." << std::endl;
        return -1;
    }

    while(std::getline(in, line))
    {
        PersonInfo info;
        record.clear(); // 重复使用字符串流时，每次都要调用 clear
        record.str(line);
        record >> info.name;
        while(record >> word)
        {
            info.phones.push_back(word);
        }
        people.push_back(info);
    }

    std::ostringstream os;
    for(const auto &entry : people)
    {
        std::ostringstream formatted, badNums;
        for(const auto &nums : entry.phones)
        {
            if(!valid(nums))
            {
                badNums << " " << nums;
            }
            else
            {
                formatted << " " << format(nums);
            }
        }
        if(badNums.str().empty())
        {
            os << entry.name << " " << formatted.str() << std::endl;
        }
        else
        {
            std::cerr << "input error: " << entry.name << " invalid number(s) " << badNums.str() << std::endl;
        }
    }

    return 0;
}